package api

import (
	"api/pkgs"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Upload(c *gin.Context) {
	file, err := c.FormFile("img")
	if err != nil {
		return
	}
	if file.Size > 2*1024*1024 {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "文件不能大于2MB",
			"data": nil,
		})
		return
	}
	dsf := "C:\\Users\\17363\\Desktop\\bina\\api\\oss\\oss" + file.Filename

	c.SaveUploadedFile(file, dsf)

	pkgs.Upload(file.Filename, dsf)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "文件上传成功",
		"data": "https://2303aly.oss-cn-shanghai.aliyuncs.com/" + file.Filename,
	})
}
